package CYClassDemo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatDemo {
    public static void main(String[] args) throws ParseException {
        Date date = new Date();
        System.out.println(date);
        //设置格式化的规则
        String s = "yyyy/MM/dd hh:mm:ss";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(s);
        //格式化成对应的形式
        String format = simpleDateFormat.format(date);
        System.out.println(format);
        //还可以反向解析格式化好的字符串
        Date parse = simpleDateFormat.parse(format);
        System.out.println(parse);
        //定义对象
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
        String format1 = simpleDateFormat1.format(new Date());
        System.out.println(format1);

    }
}
